package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import com.lanyan.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.EvaluateMapper;
import com.lanyan.system.domain.Evaluate;
import com.lanyan.system.domain.vo.EvaluateVo;
import com.lanyan.system.service.IEvaluateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 评价Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class EvaluateServiceImpl  extends ServiceImpl<EvaluateMapper,Evaluate> implements IEvaluateService

{
    @Autowired
    private EvaluateMapper evaluateMapper;

    /**
     * 查询评价
     *
     * @param evaluateId 评价主键
     * @return 评价
     */
    @Override
    public Evaluate selectEvaluateByEvaluateId(Long evaluateId)
    {
        return this.getById(evaluateId);
    }

    /**
     * 查询评价Vo列表
     *
     * @param evaluate 评价
     * @return 评价
     */
    @Override
    public List<EvaluateVo> selectEvaluateVoList(Evaluate evaluate)
    {
        return selectEvaluateList(evaluate)
                .stream()
                .map(x -> {
                    EvaluateVo evaluateVo = new EvaluateVo();
                    BeanUtils.copyBeanProp(evaluateVo,x);
                    return evaluateVo;
                })
                .collect(Collectors.toList());
    }
    /**
     * 查询评价列表
     *
     * @param evaluate 评价
     * @return 评价
     */
    @Override
    public List<Evaluate> selectEvaluateList(Evaluate evaluate)
    {
        LambdaQueryChainWrapper<Evaluate> wrapper = this.lambdaQuery().eq(Evaluate::getDelFlag,"0");
        if (evaluate.getAccountId() != null) {
            wrapper.eq(Evaluate::getAccountId, evaluate.getAccountId());
        }
        if (evaluate.getOrdersId() != null) {
            wrapper.eq(Evaluate::getOrdersId, evaluate.getOrdersId());
        }
        if (evaluate.getCourierId() != null) {
            wrapper.eq(Evaluate::getCourierId, evaluate.getCourierId());
        }
        if (evaluate.getProductId() != null) {
            wrapper.eq(Evaluate::getProductId, evaluate.getProductId());
        }
        if (StringUtils.isNotEmpty(evaluate.getSpeed())) {
            wrapper.eq(Evaluate::getSpeed, evaluate.getSpeed());
        }
        if (StringUtils.isNotEmpty(evaluate.getManner())) {
            wrapper.eq(Evaluate::getManner, evaluate.getManner());
        }
        if (StringUtils.isNotEmpty(evaluate.getDistribution())) {
            wrapper.eq(Evaluate::getDistribution, evaluate.getDistribution());
        }
        if (StringUtils.isNotEmpty(evaluate.getContent())) {
            wrapper.eq(Evaluate::getContent, evaluate.getContent());
        }
        if (StringUtils.isNotEmpty(evaluate.getImage())) {
            wrapper.eq(Evaluate::getImage, evaluate.getImage());
        }
        if (StringUtils.isNotEmpty(evaluate.getType())) {
            if(StringUtils.equals(evaluate.getType(),"0")){
                wrapper.isNull(EvaluateVo::getCourierId);
            }else {
                wrapper.isNotNull(EvaluateVo::getCourierId);
            }
        }
        if (StringUtils.isNotEmpty(evaluate.getT())) {
            switch (evaluate.getT()){
                case "0":
                    wrapper.eq(EvaluateVo::getManner,5);
                    break;
                case "1":
                    wrapper.between(EvaluateVo::getManner,2,3);
                    break;
                case "2":
                    wrapper.between(EvaluateVo::getManner,0,1);
                    break;
                case "3":
                    wrapper.isNull(EvaluateVo::getImage);
                    break;
            }
        }
        return wrapper.list();
    }

        /**
         * 新增评价
         *
         * @param evaluate 评价
         * @return 结果
         */
    @Override
        public boolean insertEvaluate(Evaluate evaluate)
        {
                    evaluate.setCreateTime(DateUtils.getNowDate());
                return this.save(evaluate);
        }

        /**
         * 修改评价
         *
         * @param evaluate 评价
         * @return 结果
         */
    @Override
        public boolean updateEvaluate(Evaluate evaluate)
        {
                    evaluate.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(evaluate);
        }

        /**
         * 批量删除评价
         *
         * @param evaluateIds 需要删除的评价主键
         * @return 结果
         */
    @Override
        public boolean deleteEvaluateByEvaluateIds(Long[] evaluateIds)
        {
            return this.lambdaUpdate().set(Evaluate::getDelFlag,"1").in(Evaluate::getEvaluateId,evaluateIds).update();
        }

        /**
         * 删除评价信息
         *
         * @param evaluateId 评价主键
         * @return 结果
         */
    @Override
        public boolean deleteEvaluateByEvaluateId(Long evaluateId)
        {
            return this.lambdaUpdate().set(Evaluate::getDelFlag,"1").eq(Evaluate::getEvaluateId,evaluateId).update();
        }
    }
